<?php
include 'connect_db.php';

// username and password sent from form
$myusername     =$_POST['myusername'];
$mypassword1    =$_POST['mypassword1'];
$mypassword2    =$_POST['mypassword2'];

/*
echo $myusername;
echo $mypassword1;
echo $mypassword2;
*/

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword1 = stripslashes($mypassword1);
$mypassword2 = stripslashes($mypassword2);
$myusername = mysql_real_escape_string($myusername);
$mypassword1 = mysql_real_escape_string($mypassword1);
$mypassword2 = mysql_real_escape_string($mypassword2);

if($mypassword1==$mypassword2){

    //echo "Password match";
    $sql="SELECT * FROM $tbl_name WHERE email_adress='$myusername'";
    $result=mysql_query($sql);
    //echo $result;
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    // If result matched $myusername and $mypassword, table row must be 1 row

    if($count==0){
        // Register $myusername, $mypassword and redirect to file "login_success.php"
        $sql="INSERT INTO $tbl_name (email_adress,password) VALUES ('$myusername','$mypassword1')";
        $result=mysql_query($sql);
        session_start();
        session_register("myusername");
        session_register("mypassword");
        $myusername=$_POST['myusername'];
        $mypassword=$_POST['mypassword1'];
        header("location:board.php");
    }
    else {
        echo "Vous êtes déjà dans la base, enregistrez vous";
    }
}
else{
    echo "Password mismatch";
}
?> 
